#include <stdio.h>

#include "ohos_init.h"
#include "cmsis_os2.h"

#include "hi_gpio.h"
#include "hi_io.h"
#include "hi_pwm.h"


static void PwmGpioTask(void *arg){
    (void)arg;
    const int NumLevels = 100;

    for (int i = 1; i < NumLevels; i++)
    {
        hi_pwm_start(HI_PWM_PORT_PWM0, 65400/i, 65400);
        osDelay(10);
        hi_pwm_stop(HI_PWM_PORT_PWM0);
    }
}


static void PwmGpioEntry(void){
    printf("Led Test!\n");
    osThreadAttr_t attr;

    hi_gpio_init();
    hi_io_set_func(9, HI_IO_FUNC_GPIO_9_PWM0_OUT);
    hi_pwm_init(HI_PWM_PORT_PWM0);

    attr.name = "PwmGpioTask";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 1024;
    attr.priority = 25;

    if (osThreadNew(PwmGpioTask, NULL, &attr) == NULL) {
        printf("[LedExample] Falied to create LedTask!\n");
    }
}

SYS_RUN(PwmGpioEntry);

